#include "editor_win.h"



EditorWin::EditorWin(QWidget *parent)
    :QWidget(parent)
{
    qDebug()<<"Create: EditorWin";
    this->file_name = "others/nodestyle.qss";
    //qDebug()<<QDir::currentPath();

    this->layout = std::make_shared<QVBoxLayout>(); // 垂直布局
    this->editorScene = std::make_shared<EditorScene>();
    this->view = std::make_shared<EditorView>(this->editorScene,this);      // 设置view
    this->tempItem = nullptr;  // 空指针

    /*
     * old for unique_ptr but now is shared_ptr
        this->editorScene = std::make_unique<EditorScene>(); for c++14
        below for c++11
        std::unique_ptr<EditorScene>tempScene(new EditorScene());
        this->editorScene.reset(tempScene.release());  //tempScene所指对象所有权转移到editorScene
        std::unique_ptr<EditorView>tempView(new EditorView(std::move(this->editorScene),this));    // 设置view
        this->view.reset(tempView.release());
    */
    this->layout->addWidget(this->view.get());     //将view添加到布局中

    this->setGeometry(200,200,800,600);
    this->layout->setContentsMargins(0,0,0,0);  //与四周边缘距离为0
    this->setLayout(this->layout.get());  // 设置布局


    this->LoadStyleSheet();
    this->setWindowTitle("NewEditor");
    this->show();
}

EditorWin::~EditorWin()
{
    this->layout.reset();
}



void EditorWin::LoadStyleSheet(){
    qDebug()<<"qss load:"<<this->file_name;
    qDebug()<<"----------";

    QFile file(this->file_name);
    file.open(QFile::ReadOnly | QFile::Text);  // 读取文件全部内容，使用tr()函数将其转换为QString类型
    QString stylesheet = QObject::tr(file.readAll());
    qApp->setStyleSheet(stylesheet);
    file.close();
}
